package cn.cxq.learning.stack;

public class Client {

    public static void main(String[] args) {

        ArrayStack arrayStack = new ArrayStack(5);

        arrayStack.push(10.23);
        arrayStack.push(20.435);
        arrayStack.push(30.344);
        arrayStack.push(40.55);
        arrayStack.push(50.33);
        arrayStack.push(60.44);

        stackList(arrayStack);

        System.out.println("------------------------------------------");

        stackPop(arrayStack);
        stackPop(arrayStack);
        stackPop(arrayStack);
        stackPop(arrayStack);
        stackPop(arrayStack);
        stackPop(arrayStack);

        stackList(arrayStack);

        System.out.println("------------------------------------------");

        SimpleCalculator simpleCalculator = new SimpleCalculator();

        try {
            System.out.println(simpleCalculator.calculate("3.3+4*5.13/4-2+4"));
        }catch (RuntimeException e){
            System.out.println(e.getMessage());
        }
        try {
            System.out.println(simpleCalculator.calculate("3.3+4*5.13/4-2+4"));
        }catch (RuntimeException e){
            System.out.println(e.getMessage());
        }
        try {
            System.out.println(simpleCalculator.calculate("1+5.2*2+3*4"));
        }catch (RuntimeException e){
            System.out.println(e.getMessage());
        }

        System.out.println("------------------------------------------");

        String reversePolish = ReversePolish.infixToPostfix("1.8+((2+3.5)*4)-5.4");

        try {
        System.out.println("逆波兰表达式：" + reversePolish);
        System.out.println("逆波兰表达式计算结果：" + ReversePolish.calculate(reversePolish));
        }catch (RuntimeException e){
            System.out.println(e.getMessage());
        }

    }

    private static void stackList(ArrayStack arrayStack) {
        try {
            arrayStack.list();
        }catch (RuntimeException e){
            System.out.println(e.getMessage());
        }
    }

    private static void stackPop(ArrayStack arrayStack) {

        try {
            System.out.println("出栈值为" + arrayStack.pop());
        }catch (RuntimeException e){
            System.out.println(e.getMessage());
        }
    }
}
